﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
using System.Windows.Media;

using NUnit.Framework;

using Uhi.Libraries.Test;

using Uhi.Applications.FileAid.Interactivity;

namespace FileAidTest.Interactivity
{
    [TestFixture]
    public class ListSelectBehaviorTest
    {
        #region 正常ケース
        [Test, STAThread]
        public void 正常ケース()
        {
            var textFactory = new FrameworkElementFactory(typeof(TextBox));
            var dataTemplate = new DataTemplate();
            dataTemplate.VisualTree = textFactory;

            var listbox = new ListBox();
            listbox.ItemTemplate = dataTemplate;
            listbox.ItemsSource = new[] { "a", "b", "c" };

            Interaction.GetBehaviors(listbox).Add(new ListSelectBehavior());

            var window = new Window();
            window.Content = listbox;

            window.Show();

            var container = listbox.ItemContainerGenerator.ContainerFromIndex(1) as ListBoxItem;
            var border = VisualTreeHelper.GetChild(container, 0);
            var presenter = VisualTreeHelper.GetChild(border, 0);
            var textbox = VisualTreeHelper.GetChild(presenter, 0) as TextBox;

            textbox.Focus();

            listbox.SelectedIndex.Is(1);

            window.Close();
        }
        #endregion
    }
}
